package com.whmskj.xjlhsc.mobie.ProductionManagement.mapper;

import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.entity.ShiftDate;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OutputEnergyConsumptionMapper {

    List<DailyProcessStatsVO> getDailyProcessStats(
            @Param("process") String process,
            @Param("endDate") LocalDate endDate,
            @Param("startDate") LocalDate startDate
    );

    List<ShiftVarietyStatsVO> getShiftVarietyStats(
            @Param("process") String process,
            @Param("date") LocalDate date,
            @Param("shiftType") String shiftType  // 改为更通用的名称，避免混淆
    );

    List<EnergyConsumptionOfFineSandProductionVO> getMonthlyFineSandStats(@Param("process") String process, @Param("startDate") String startDate, @Param("endDate") String endDate);

    List<MonthlyVarietyDetailVO> getMonthlyVarietyStats(@Param("process") String process, @Param("monthStart") String monthStart, @Param("monthEnd") String monthEnd);

    ShiftDate getCrewData(@Param("monthStr") String monthStr, @Param("process") String process);

    ShiftDate getCrewDataYi(@Param("monthStr") String monthStr, @Param("process") String process);

    ShiftDate getCrewDataBing(@Param("monthStr") String monthStr, @Param("process") String process);

    @Select("SELECT SUM(b.actualyieldkg) AS lateYield\n" +
            "FROM catalogueOfGy02Stations s\n" +
            "    INNER JOIN shachang_sb_banyield b ON s.id = b.mesid\n" +
            "WHERE s.process = #{process}\n" +
            "    AND b.day LIKE CONCAT(#{monthStr}, '%')\n" +
            "    AND b.shift = '夜班'")
    Float getLateYield(@Param("monthStr") String monthStr, @Param("process") String process);

    @Select("SELECT AVG(b.actualyieldkg / b.yieldkg * 100) AS lateEfficiency\n" +
            "FROM catalogueOfGy02Stations s\n" +
            "    INNER JOIN shachang_sb_banyield b ON s.id = b.mesid\n" +
            "WHERE s.process = #{process}\n" +
            "    AND b.day LIKE CONCAT(#{monthStr}, '%')\n" +
            "    AND b.shift = '夜班'")
    Float getLateEfficiency(@Param("monthStr") String monthStr, @Param("process") String process);

    @Select("SELECT SUM(b.actualyieldkg) AS earlyYield\n" +
            "FROM catalogueOfGy02Stations s\n" +
            "    INNER JOIN shachang_sb_banyield b ON s.id = b.mesid\n" +
            "WHERE s.process = #{process}\n" +
            "    AND b.day LIKE CONCAT(#{monthStr}, '%')\n" +
            "    AND b.shift = '白班'")
    Float getEarlyYield(@Param("monthStr") String monthStr, @Param("process") String process);

    @Select("SELECT AVG(b.actualyieldkg / b.yieldkg * 100) AS earlyEfficiency\n" +
            "FROM catalogueOfGy02Stations s\n" +
            "    INNER JOIN shachang_sb_banyield b ON s.id = b.mesid\n" +
            "WHERE s.process = #{process}\n" +
            "    AND b.day LIKE CONCAT(#{monthStr}, '%')\n" +
            "    AND b.shift = '白班'")
    Float getEarlyEfficiency(@Param("monthStr") String monthStr, @Param("process") String process);

    List<ShiftProductionEnergyVO> getShiftProductionEnergy(@Param("process") String process, @Param("date") LocalDate date,
                                                           @Param("DayShiftOrEveningShift") String DayShiftOrEveningShift);

//    List<YieldAndEfficiency> getYieldAndEfficiencyList(@Param("monthStr") String monthStr, @Param("process") String process);
}
